#! /usr/bin/python3
# encoding : utf-8

import random
import datetime
from datetime import datetime
import time


class Date:
    Year = 1950
    Month = 1
    Day = 1

    def __init__(self, year=1950, month=1, day=1):
        self.Year = year
        self.Month = month
        self.Day = day

    def ToString(self):
        return "{0}-{1}-{2}".format(self.Year, self.Month, self.Day)

    @staticmethod
    def FromString(string):
        nums = string.split('-')
        year = int(nums[0], 10)
        month = int(nums[1], 10)
        day = int(nums[2], 10)
        return Date(year, month, day)

    @staticmethod
    def RandomDate(from_year=1950, from_month=1, from_day=1, from_string=""):
        if not from_string == "":
            from_date = Date.FromString(from_string)
            from_year = from_date.Year
            from_month = from_date.Month
            from_day = from_date.Day
        start_time = datetime(from_year, from_month, from_day, 0, 0, 0)
        end_time = datetime.now()
        start = int(time.mktime(tuple(start_time.timetuple()[0:9])))
        end = int(time.mktime(tuple(end_time.timetuple()[0:9])))
        t = random.randint(start, end)
        tt = time.localtime(t)
        year = tt[0]
        month = tt[1]
        day = tt[2]
        return Date(year, month, day)
